﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_GetAllChildPosition_V2]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_GetAllChildPosition_V2];
GO
CREATE PROCEDURE [dbo].[sproc_GetAllChildPosition_V2]
    @Position_ID int
/*

======================================================
功能:    得到此职位所有的子职位
参数:
    @Position_id int        :    职位ID
======================================================

*/
AS
BEGIN
SET NOCOUNT ON

DECLARE @subtree TABLE ( Position_ID INT NOT NULL );

-- Select all recursive child positions
INSERT INTO @subtree (Position_ID) exec dbo.[sproc_GetAllChildPositionID_V2] @Position_ID;

-- Return all the records
SELECT
    p.*
FROM
    dbo.UDS_Position p,
    @subtree t
WHERE
    p.Position_ID = t.Position_ID;

END
GO